$('#sidebar').affix({
    offset: {
        top: 245
    }
});

//Delete cart
function delete_cart(i)
{
    var id = $('#item'+i).val();
    document.getElementById('qty'+i).value = 0;
    var url = "http://localhost/dota2shopvn/cart/load_cart";
    document.getElementById('updatecart').click();
}

// Popover
$(document).ready(function(){
    //$('a').popover();
});

//Ajax Homepage
$(document).ready(function(){
    ajax_hot_item();
    ajax_new_release_item();
    ajax_top_sellers_item();
    check_username();
    check_pass();

    var base_url = "http://localhost/dota2shopvn/";

    function ajax_new_release_item() {
        $('#tabheader1').click(function () {
            url = base_url+"Ajax_Controller/new_release_item";
            $('#tabdata1').load(url);
        });
    }

    function ajax_top_sellers_item() {
        $('#tabheader2').click(function () {
            url = base_url+"Ajax_Controller/top_sellers_item";
            $('#tabdata2').load(url);
        });
    }

    function ajax_hot_item() {
        $('#tabheader3').click(function () {
            url = base_url+"Ajax_Controller/hot_item";
            $('#tabdata3').load(url);
        });
    }

    function check_username()
    {
        $('#regusername').on('keyup', function() {
            var regusername = $('#regusername').val();
            $.ajax({
                type: 'POST',
                url: '/dota2shopvn/account/checkusername/'+regusername,
                success: function(dataresult){
                    if(dataresult)
                    {
                        document.getElementById('btnsignup').disabled = true;
                        $('#regusername').css('background-color', '#ff6666');
                        document.getElementById('checkusername').innerHTML="Username is Unavailable";
                    }
                    else
                    {
                        document.getElementById('btnsignup').disabled = false;
                        document.getElementById('checkusername').innerHTML="Username is Available";
                        $('#regusername').css('background-color', '#66cc66');
                    }
                }
            });
        });
    }

    // Check password
    function check_pass()
    {
        $('#regpw, #reregpw').on('keyup', function(){
            if ($('#regpw').val() == $('#reregpw').val()) {
                document.getElementById('checkpw').innerHTML="Password is Match";
                $('#regpw').css('background-color', "#66cc66");
                $('#reregpw').css('background-color', "#66cc66");
                document.getElementById('btnsignup').disabled = false;
            }
            else {
                document.getElementById('checkpw').innerHTML="Password is not Match";
                $('#regpw').css('background-color', "#ff6666");
                $('#reregpw').css('background-color', "#ff6666");
                document.getElementById('btnsignup').disabled = true;
            }
        });

        $('#newpass, #renewpassword').on('keyup', function(){
            if ($('#newpass').val() == $('#renewpassword').val()) {
                document.getElementById('checkpw1').innerHTML="Password is Match";
                $('#newpass').css('background-color', "#66cc66");
                $('#renewpassword').css('background-color', "#66cc66");
                document.getElementById('ChangePW').disabled = false;
            }
            else {
                document.getElementById('checkpw1').innerHTML="Password is not Match";
                $('#newpass').css('background-color', "#ff6666");
                $('#renewpassword').css('background-color', "#ff6666");
                document.getElementById('ChangePW').disabled = true;
            }
        });
        
    }
    

    
});



